/* follow the changes in the observing sources */
package Observing;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import Algo.Algo;
import Command.DirectCommand;

import DataBase.MenuTag_File;

public class WatchDirUpdate {
	private DirectCommand command;
	
	public interface Update {
		public boolean execute(String action, Path child);	
	}	
	public class ENTRY_MODIFY implements Update{
		public boolean execute(String action, Path child){
			//we dont really need this... we can delete and create new
			//////////////System.out.println("watch dir update: ENTRY_MODIFY: "+child);
			return true;
		}
	}
	public class ENTRY_DELETE  implements Update  {	
		public boolean execute(String action, Path child){
			command.delFile(child);
			/////////////System.out.println("watch dir update: ENTRY_DELETE: "+child);
			return true;
		}
	}
	public class ENTRY_CREATE implements Update  {	
		public boolean execute(String action, Path child){ 
			command.addFile(child);
			//////////////System.out.println("watch dir update: ENTRY_CREATE: "+child);
			return true;
		}
	}
	private HashMap <String,Update> hashMap;
	
	public WatchDirUpdate(ArrayList<Algo> algo,MenuTag_File dataBase){
		command=new DirectCommand(algo,dataBase);
		hashMap = new HashMap<String, Update>();
		hashMap.put("ENTRY_MODIFY", new ENTRY_MODIFY());
		hashMap.put("ENTRY_DELETE", new ENTRY_DELETE());
		hashMap.put("ENTRY_CREATE", new ENTRY_CREATE());
	}
	public void set(String action, Path child) {
		try{
			if (hashMap.get(action) == null){
					System.out.println("Error: command not found.");
			}else{
				(hashMap.get(action)).execute(action,child);			
			}
		}catch(Exception e){
			/////////////////System.out.println("Error: command not found.");
		}	
	}
}